package lance.honeydew.action;

import java.util.ArrayList;
import java.util.List;

import lance.honeydew.bean.OrderDetail;
import lance.honeydew.bean.OrderInformation;
import lance.honeydew.bean.UserMember;
import lance.honeydew.service.ShopService;

import org.apache.log4j.Logger;

public class OrderListAction extends BaseAction {

	private static final Logger logger = Logger.getLogger(OrderListAction.class);
	
	/*Bean*/
	private ShopService shopService;
	private OrderInformation orderInformationBo;
	private Long orderInforSeqid;
	private List<OrderInformation> orderInforList;
	private List<OrderDetail> orderDetailList;

	public ShopService getShopService() {
		return shopService;
	}

	public void setShopService(ShopService shopService) {
		this.shopService = shopService;
	}

	public OrderInformation getOrderInformationBo() {
		return orderInformationBo;
	}

	public void setOrderInformationBo(OrderInformation orderInformationBo) {
		this.orderInformationBo = orderInformationBo;
	}

	public Long getOrderInforSeqid() {
		return orderInforSeqid;
	}

	public void setOrderInforSeqid(Long orderInforSeqid) {
		this.orderInforSeqid = orderInforSeqid;
	}
	
	public List<OrderInformation> getOrderInforList() {
		return orderInforList;
	}

	public void setOrderInforList(List<OrderInformation> orderInforList) {
		this.orderInforList = orderInforList;
	}

	public List<OrderDetail> getOrderDetailList() {
		return orderDetailList;
	}

	public void setOrderDetailList(List<OrderDetail> orderDetailList) {
		this.orderDetailList = orderDetailList;
	}

	/*Action*/
	public String execute() {
		
		UserMember sessionUser = getSessionUserMember();
		
		if (sessionUser != null) {
			setUserMemberBo(sessionUser);
		} else {
			return ERROR;
		}
		
		return SUCCESS;
	}
	
	/**
	 * orderList01.jsp
	 * @return
	 */
	public String orderList01() {
		
		try {
			
			UserMember sessionUser = getSessionUserMember();
			
			if (sessionUser != null) {
				
				if (sessionUser.getUserid() != null) {
					
					UserMember userObj = shopService.findUserMemberByUserId(sessionUser.getUserid());
					
					if (userObj.getOrderInformationSet() != null) {
						orderInforList = new ArrayList(userObj.getOrderInformationSet());
					}
					
				} else {
					return ERROR;
				}				
				
			} else {
				return ERROR;
			}
			
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return "orderList01";
	}
	
	/**
	 * orderList01.jsp
	 * @return
	 */
	public String orderList0101() {
		
		try {
			
			UserMember sessionUser = getSessionUserMember();
			
			if (sessionUser != null) {
				
				if (orderInforSeqid != null) {
					
					OrderInformation orderInforObj = shopService.findOrderInformationBySeqId(orderInforSeqid);
					
					if (orderInforObj != null) {
						
						setOrderInformationBo(orderInforObj);
						
						orderDetailList = new ArrayList(orderInforObj.getOrderDetailSet());
						
					} else {
						return ERROR;
					}
					
				} else {
					return ERROR;
				}
				
			} else {
				return ERROR;
			}
			
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return "orderList0101";
	}
}
